package com.wise.service.portal.content.productindustry.product;

import cn.hutool.core.collection.CollectionUtil;
import com.wise.entities.content.Product;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import com.wise.framework.validation.Precondition;
import com.wise.summer.v1.portal.content.productindustry.GetProductIndustryById;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;

import static com.wise.model.content.ContentErrMsgs.Err_002000250009;

/**
 * @author shaoming
 * @date 2019-09-09
 */
@Service
@SummerService
public class GetProductIndustryByIdService implements SummerServiceBean<GetProductIndustryById> {

	@Override
	public void sum(GetProductIndustryById summer) {
		SqlSelect sqlSelect = SqlSelect.selec("*")
				.fromClassName(Product.class)
				.eq(Product._id, summer.getId())
				.eq(Product._categoryType, 1);

		List<GetProductIndustryById.Result> productList = DaoList.s(GetProductIndustryById.Result.class, sqlSelect, 0, 1);

		GetProductIndustryById.Result product = CollectionUtil.getFirst(productList);
		Precondition.checkNotNull(product, Err_002000250009);

		summer.setSummerResult(product);
	}
}
